package com.zjuee.web.ledger.controller;

import com.zjuee.base.bean.response.R;
import com.zjuee.base.constant.Common;
import com.zjuee.base.dto.common.login.LoginDto;
import com.zjuee.service.PlanService;
import com.zjuee.service.PlanTreatService;
import com.zjuee.base.model.common.plan.PlanTreat;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

@Slf4j
@RestController
@RequestMapping(Common.Service.ZJUEE_CO_MAIN_PLAN_URL_PREFIX)
public class PlanTreatController  {

    @Resource
    private PlanTreatService planTreatService;
    @Resource
    private PlanService planService;
    @Resource
    private LoginDto loginDto;

     
    public R<Long> addPlanTreat(PlanTreat planTreat) {
        if (planTreat.getWpiId() == null) {
            return R.fail("计划ID为空！");
        }
        return R.ok(planTreatService.add(planTreat));
    }

     
    public R<Boolean> updatePlanTreat(PlanTreat planTreat) {
        if (planTreat.getWpiId() == null) {
            return R.fail("计划ID为空！");
        }
        return R.ok(planTreatService.update(planTreat));
    }

//     
//    public R<Boolean> deletePlanTreat(@NotNull Long id, @NotNull String wpiYear) {
//        Boolean type = false;
//        if (wpiYear.equals(DateUtils.getYear(new Date()))) {
//            type = planTreatService.delete(id, loginDto.getPlanId());
//        } else {
//            PlanInfo plan = planService.selectInfoByBciId(loginDto.getOrgBusinessId(), wpiYear);
//            if (plan != null) {
//                type = planTreatService.delete(id, plan.getId());
//            } else {
//                return R.fail("删除原材料信息失败");
//            }
//        }
//        if (type) {
//            return R.ok("success");
//        }
//        return R.fail("删除原材料信息失败");
//    }

     
    public R<PlanTreat> selectById(@NotNull Long id, @NotNull Long validateId) {
        try {
            PlanTreat planTreat = planTreatService.selectById(id, validateId);
            if (planTreat == null)
                return R.fail("id与validateId不符");
            return R.ok(planTreat);
        } catch (Exception e) {
            return R.fail("id不存在");
        }
    }

     
    public R<List<PlanTreat>> getPlanTreat(PlanTreat planTreat) {
        return R.ok(planTreatService.getPlanTreat(planTreat));
    }
}
